<!DOCTYPE html>
<html>
<head>
	
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title>蹭一族</title>
	<!-- Bootstrap 3.3.5 -->
  <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css"  />
  <!-- Font Awesome -->
  <link rel="stylesheet" href="/static/awesome/css/font-awesome.min.css" /> 
  <!-- Ionicons -->
  <link rel="stylesheet" href="/static/ionicon/css/ionicons.min.css" />
  <!-- Theme style -->
  <link rel="stylesheet" href="/static/dist/css/AdminLTE.min.css" />
  <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
  <link rel="stylesheet" href="/static/dist/css/skins/_all-skins.min.css" />
   <link rel="stylesheet" href="/static/js/img/img.css" />
   
 <!-- 引入uploadify -->
<link href="/static/js/uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<link rel="stylesheet" href="/static/js/img/img.css" type="text/css">
<!-- ./wrapper -->	

<link href="/static/bootstrapValidate/css/bootstrapValidator.min.css" rel="stylesheet" />


</head>
<body class="hold-transition skin-blue sidebar-mini">
	<form id="validateForm"
	  data-bv-message="验证不通过"
	  data-bv-feedbackicons-valid="fa fa-check"
	  data-bv-feedbackicons-invalid="fa fa-times"
	  data-bv-feedbackicons-validating="fa fa-refresh"
	 >
	 <div class="box box-danger">
            <div class="box-header with-border">
            	<input name="id" type="hidden"  />
            </div>
            <div class="box-body">
              <div class="row">
                <div class="col-xs-6">
                   <div class="form-group">
	                  <label for="exampleInputEmail1">账号</label>
	                  <input type="text" class="form-control"  
	                  data-bv-stringlength="true" data-bv-stringlength-max="20" data-bv-stringlength-message="请输入少于20字"
	                  data-bv-notempty="true"  data-bv-notempty-message="账号不能为空" name="account" id="account" placeholder="请输入账号">
	                </div>
	                <div class="form-group" id="pwd1"  >
	                  <label for="exampleInputEmail1">密码</label>
	                  <input type="password" class="form-control" 
	                   data-bv-identical="true" data-bv-identical-field="confirmPassword" data-bv-identical-message="两次输入密码不一致"
	                   data-bv-stringlength="true" data-bv-stringlength-max="20" data-bv-stringlength-message="请输入少于20字"
	                   data-bv-notempty="true" data-bv-notempty-message="密码不能为空"  name="password" id="password" placeholder="请输入密码">
	                </div>
	                <div class="form-group" id="pwd2"  >
	                  <label for="exampleInputEmail1">确认密码</label>
	                  <input type="password" class="form-control" 
	                  data-bv-identical="true" data-bv-identical-field="password" data-bv-identical-message="两次输入密码不一致"
	                   data-bv-stringlength="true" data-bv-stringlength-max="20" data-bv-stringlength-message="请输入少于20字"
	                  data-bv-notempty="true" data-bv-notempty-message="确认密码不能为空" id="confirmPassword"  name="confirmPassword" placeholder="请再次输入密码">
	                </div>
	                 <div class="form-group">
	                  <label for="exampleInputEmail1">酒水额度</label>
	                  <input type="text" 
	                    data-bv-between-inclusive="true" min="0" max="99999" data-bv-between-message="请输入0-99999之间的数字"
	                  class="form-control" id="wineUnit" name="wineUnit" placeholder="请输入每月免费酒水最大额度">
	                </div>
	                <div class="form-group">
	                  <label for="exampleInputEmail1">酒水赠送</label>
	                  <input type="text" 
	                    data-bv-between-inclusive="true" min="0" max="1000" data-bv-between-message="请输入0-1000之间的数字"
	                  class="form-control" id="wineRate" name="wineRate" placeholder="请输入酒水赠送比例（千分之）">
	                </div>
	                <div class="form-group" id="area1" >
	                  <label for="exampleInputEmail1">市</label>
	                  <select type="text" class="form-control" id="cityCode" placeholder="请输入地区" name="cityCode">
	                  </select>
	                </div>
	                 <div class="form-group" id="area2"  >
	                  <label for="exampleInputEmail1">区</label>
	                  <select type="text" class="form-control" id="quCode" placeholder="请输入地区" name="quCode">
	                  </select>
	                </div>
	                <div class="form-group" id="area3"  >
	                  <label for="exampleInputEmail1">商圈</label>
	                  <select type="text"
	                   class="form-control" id="areaCode" placeholder="请输入商圈" name="areaCode">
	                  </select>
	                </div>
	                
	                <div class="form-group">
	                  <label for="exampleInputEmail1">Logo</label>
	                  <input id="logo" multi="false" type="file" showImage="true"  showBtn='true' fileType="*.jpg;*.png" fileSize="1MB" buttonText="Logo"></input>
                	  <span ><span style='color:red'>*</span>200*200</span>
	                </div>
                </div>
                <div class="col-xs-6">
                   <div class="form-group">
	                  <label for="exampleInputEmail1">商家名称：</label>
	                  <input type="text" 
	                   data-bv-notempty="true" data-bv-notempty-message="商家名称不能为空" 
	                  data-bv-stringlength="true" data-bv-stringlength-max="20" data-bv-stringlength-message="请输入少于20字"
	                  class="form-control" id="name" placeholder="商家名称" name="name">
	                </div>
	                <div class="form-group">
	                  <label for="exampleInputEmail1">电话号码</label>
	                  <input
	                    data-bv-notempty="true" data-bv-notempty-message="电话号码不能为空" 
	                   data-bv-phone-message="手机号码格式不正确" 
	                   type="text" class="form-control" id="phone" placeholder="请输入联系方式"name="phone" >
	                </div>
	                <div class="form-group">
	                  <label for="exampleInputEmail1">地址</label>
	                  <input 
	                  type="text" class="form-control" id="address" placeholder="请输入地址" name="address">
	                </div>
	                 <div class="form-group">
	                  <label for="exampleInputEmail1">经纬度</label>
	                  <input type="hidden" name="lat" id="lat" /><input type="hidden" name="lng" id="lng" />
	                  <button type="button" class="btn bg-olive margin" onclick="showmap()" >地图</button>
	                </div>
	                <div class="form-group">
	                  <label for="exampleInputEmail1">均价</label>
	                  <input 
	                  data-bv-notempty="true" data-bv-notempty-message="均价不能为空" 
	                  data-bv-numeric="true"  data-bv-numeric-message="请输入数字"
	                  type="text" class="form-control" id="avgScore" placeholder="请输入均价" name="avgPrice">
	                </div>
	                <div class="form-group">
	                  <label for="exampleInputEmail1">酒水起送金额</label>
	                  <input 
	                  data-bv-notempty="true" data-bv-notempty-message="酒水起送金额不能为空" 
	                   data-bv-between-inclusive="true" min="0" max="99999" data-bv-between-message="请输入0-99999之间的数字"
	                  type="text" class="form-control" id="wineBegin" placeholder="请输入酒水起送金额" name="wineBegin">
	                </div>
	                <div class="form-group">
	                  <label for="exampleInputEmail1">分类</label>
	                  <select 
	                  type="text" class="form-control" id="cateCode" placeholder="请输入均价" name="cateCode">
	                  </select>
	                </div>
	              
	                <div class="form-group">
	                  <label for="exampleInputEmail1">排序</label>
	                  <input 
	                    data-bv-notempty="true" data-bv-notempty-message="排序不能为空" 
	                    data-bv-between-inclusive="true" min="0" max="99999" data-bv-between-message="请输入0-99999之间的数字"
	                  type="text" class="form-control" id="sort" name="sort"   placeholder="请输入排序">
	                </div>
	                <div class="form-group">
	                  <label for="exampleInputEmail1">大图</label>
	                  <input id="imgs" multi="false" type="file" showImage="true"  showBtn='true' fileType="*.jpg;*.png" fileSize="1MB" buttonText="上传"></input>
                	  <span ><span style='color:red'>*</span>400*400</span>
	                </div>
                </div>
              </div>
            </div>
            <!-- /.box-body -->
             <div class="box-body pad">
             		<label for="exampleInputEmail1">商家简介</label>
                    <textarea 
                    id="info" name="info" rows="10" cols="120" placeholder="请输入商家简介" ></textarea>
            </div>
            <div class="box-body pad">
             		<label for="exampleInputEmail1">商家详情</label>
                    <textarea id="editor1"   rows="10" cols="80" style="width:100%;" ></textarea>
            </div>
            
       </div>
	</form>
<!-- jQuery 2.1.4 -->
<script src="/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="/static/js/jqueryUi.min.1.11.4.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<!-- Bootstrap 3.3.5 -->
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<!-- Morris.js charts 
<script src="/static/plugins/morris/morris.min.js"></script>
-->
<!-- Slimscroll -->
<script src="/static/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="/static/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="/static/dist/js/app.min.js"></script>

<!-- layer-->
<script src="/static/layer/layer.js"></script>

<!-- layer-->
<script src="/static/js/syUI.js"></script>



<script type="text/javascript" src="/static/js/uploadify/swfobject.js"></script>
<script type="text/javascript" src="/static/js/uploadify/jquery.uploadify.js"></script>
<!-- 引入ui扩展 -->
<script src="/static/js/core.ui.js" type="text/javascript" charset="utf-8"></script>
<!-- 引入图片裁剪-->
<link rel="stylesheet" href="/static/js/tapmodo-Jcrop-1902fbc/css/jquery.Jcrop.css" type="text/css">
<script type="text/javascript" src="/static/js/tapmodo-Jcrop-1902fbc/js/jquery.Jcrop.js"></script>
<script type="text/javascript" src="/static/js/tapmodo-Jcrop-1902fbc/js/jquery.Jcrop.min.js"></script>
<!-- 浏览大图 -->
<script type="text/javascript" src="/static/js/img/img.js"></script>

<script type="text/javascript" src="/static/js/ut.js" ></script>

<!-- 引入kindeditor控件 -->
<script src="/static/js/kindeditor-4.1.10/kindeditor-all.js" type="text/javascript" charset="utf-8"></script>
<script src="/static/bootstrapValidate/js/bootstrapValidator.min.js"></script>


<script>
	var table ;
	var id='';
	 var editor;
	<#if id??>
		id = '${id}';
	</#if>
	var openmap = function (ret) {
		if(ret){
			$("#lng").val(ret.lng);
			$("#lat").val(ret.lat);
			$("#address").val(ret.address);
		}
	}
	
	function showmap(){
		var lng =$("input[name='lng']").val();
		var lat=$("input[name='lat']").val();
		sy.amap(openmap,lat,lng);
	}
	
	var submitForm = function($dialog, $grid, $pjq) {
		if ((!id&&$('#validateForm').data('bootstrapValidator').isValid())||id) {
			var obj = sy.serializeObject($('#validateForm'));
			var logo = $('#logo').getFileId();
			var imgs = $('#imgs').getFileId();
			if(!logo||!imgs){
				$pjq.messager.e('图片未上传');
				return;
			}
			obj.logo = logo;
			obj.imgs = imgs;
			if(!id){
				if(!obj.areaCode){
					$pjq.messager.e('商圈未选择');
					return;
				}
				if(!obj.cateCode){
					$pjq.messager.e('分类未选择');
					return;
				}
			}
			if(!address||!lat||!lng){
				$pjq.messager.e('请点击地图按钮,选择一个经纬度');
				return;
			}
			if(!obj.cateCode){
				$pjq.messager.e('分类未选择');
				return;
			}
			if(obj.info&&obj.info.length>500){
				$pjq.messager.e('商家简介不能超过500字');
				return;
			}
			
			obj.detail = editor.getHtml();
			var url=sy.contextPath + '/store/save';
			$.post(url, obj, function(result) {
				if (result.code == 0) {
					$grid.fnDraw(false);
					$dialog.dialog('destroy');
				} else {
					$pjq.messager.e('添加失败,'+result.msg);
				}
			}, 'json');
		}else{
			$pjq.messager.e('请将内容填写完整');
		}
	};
	
	
	
	
	$(function(){
		editor=new HtmlEditor('#editor1');
		$.post('/storeCategory/listByLevel', {
				level : 1
			}, function(result) {
				if (result) {
					var str = "";
					$.each(result,function(i,v){
						str +="<option value='"+v.code+"' level='"+v.level+"' >"+v.name+"</option>"
					});
					$('#cateCode').html(str);
				}
			}, 'json');
		if(!id){
			$.post('/city/listByLevel', {
				level : 1
			}, function(result) {
				if (result) {
					var str = "<option value >-请选择城市-</option>";
					$.each(result,function(i,v){
						str +="<option value='"+v.code+"' level='"+v.level+"'  >"+v.name+"</option>"
					});
					$('#cityCode').html(str);
				}
			}, 'json');
			
			$('#cityCode').bind('change',function(ret){
				var code = $(this).children('option:selected').val();
				var level = $(this).children('option:selected').attr('level');
				if(!code||!level) return;
				$('#areaCode').html('');
				
				$.post('/city/listByLevel', {
					level : parseInt(level)+1 , parent:code
				}, function(result) {
					if (result) {
						var str = "<option value >-请选择城区-</option>";
						$.each(result,function(i,v){
							str +="<option value='"+v.code+"' level='"+v.level+"' >"+v.name+"</option>"
						});
						$('#quCode').html(str);
					}
				}, 'json');
			
			});
			
			$('#quCode').bind('change',function(ret){
				var code = $(this).children('option:selected').val();
				var level = $(this).children('option:selected').attr('level');
				if(!code||!level) return;
				$.post('/city/listByLevel', {
					level : parseInt(level)+1 , parent:code
				}, function(result) {
					if (result) {
						var str = "";
						$.each(result,function(i,v){
							str +="<option value='"+v.code+"' >"+v.name+"</option>"
						});
						$('#areaCode').html(str);
					}
				}, 'json');
			
			});
		}else{
			$('#area1').remove();
			$('#area2').remove();
			$('#area3').remove();
			$('#pwd1').remove();
			$('#pwd2').remove();
		}
		
		
		
		
		
		
		//sy.validateForm('#validateForm');
		 $('#validateForm').bootstrapValidator();
		 if (id != '') {
			parent.$.messager.progress({
				text : '数据加载中....'
			});
			$.post('/store/findById', {
				id : id
			}, function(result) {
				parent.$.messager.progress('close');
				if (result) {
					sy.loadForm($('#validateForm'),result);
					$('#logo').setFileId(result.logo,false,true,true);
					$('#imgs').setFileId(result.imgs,true,true,true);
					
				}
			}, 'json');
		}
	});
	 
</script>

</body>
</html>
